package com.hkbigdata.springbootdemo.controller;

import com.hkbigdata.springbootdemo.bean.Employee;
import com.hkbigdata.springbootdemo.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author liuanbo
 * @creat 2024-11-13-11:29
 * @see 2194550857@qq.com
 */
@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/getAllEmp")
    public Object getAllEmp() {
        List<Employee> all = employeeService.getAll();
        return all;
    }

    @RequestMapping("/emp")
    public Object emp(String op,Integer id,String lastname,String gender,String email) {
        // 封装数据模型
        Employee employee = new Employee(id, lastname, gender, email);
        switch (op){

            case "select": if (id == null){
                return "必须传入员工id！";
            }else {
                Employee e = employeeService.getempByid(id);
                return e == null ? "查无此人!" : e;
            }

            case "insert" : employeeService.addEmp(employee);
                return "操作完成!";

            case "update": if (id == null){
                return "必须传入员工id！";
            }else {
                employeeService.updateEmp(employee);
                return  "操作完成!";
            }

            case "delete": if (id == null){
                return "必须传入员工id！";
            }else {
                employeeService.deleteEmp(id);
                return  "操作完成!";
            }

            default: return "请正确操作";
        }
    }
}
